<template>
  <!-- 视频详情页 -->
  <div class="viedeDetails_main">
    <div class="left_box">
      <div class="left_info" v-if="awemeInfo&&awemeInfo.aweme&&awemeInfo.aweme.thumpic">
        <div class="info_box">
          <el-popover
            placement="right"
            width="200"
            popper-class="big_img"
            :visible-arrow="false"
            trigger="click">
            <img :src="awemeInfo.aweme.thumpic" class="logo" slot="reference" />
            <img :src="awemeInfo.aweme.thumpic" class="logo"/>
          </el-popover>
          <div>
            <p class="title" @click="dyVideo">{{awemeInfo.aweme.title}}</p>
            <el-popover
              placement="bottom"
              trigger="hover"
              popper-class="hot_video_popover"
              v-if="awemeInfo"
            >
              <vue-qr
                :size="150"
                :margin="0"
                :auto-color="true"
                v-if="awemeInfo&&awemeInfo.aweme.url"
                :dot-scale="1"
                :text="awemeInfo.aweme.url"
              />
              <p>【抖音扫码，查看视频】</p>
              <img slot="reference" src="@/assets/liu/goodsDetailsCode.png" />
            </el-popover>
            <!-- <el-tooltip
              class="item"
              effect="light"
              content="复制标题"
              placement="top"
              popper-class="mytooltip"
              v-clipboard:error="onError"
              v-clipboard:copy="awemeInfo.aweme.title"
              :hide-after="2000"
            >
              <div class="copylink">
                <img @click="copy" src="@/assets/liu/copy.png" />
              </div>
            </el-tooltip>-->
          </div>
        </div>
        <div class="bor_bot">
          <div class="commonStyle mar_top">
            <p>点赞总数</p>
            <p>{{format_num(awemeInfo.aweme.total_favorite)}}</p>
          </div>
          <div class="commonStyle">
            <p>评论总数</p>
            <p>{{format_num(awemeInfo.aweme.total_comment)}}</p>
          </div>
          <div class="commonStyle">
            <p>转发总数</p>
            <p>{{format_num(awemeInfo.aweme.total_share)}}</p>
          </div>
          <div class="commonStyle">
            <p>视频时长</p>
            <p>{{format_time(awemeInfo.aweme.duration)}}</p>
          </div>
          <div class="commonStyle">
            <p>发布时间</p>
            <p>{{timestamp(awemeInfo.aweme.release_time_stamp,'Y-M-D h:m:s')}}</p>
          </div>
        </div>
        <button class="add_col" @click="CancelCollection" v-if="awemeInfo.awemecollection">已收藏</button>
        <button class="add_col" v-else @click="InsertCollection">添加收藏</button>
      </div>
      <div class="bot_info">
        <template v-if="awemeInfo&&awemeInfo.author">
          <div class="bot_box">
            <img
              v-if="awemeInfo&&awemeInfo.author"
              :src="awemeInfo.author.logo"
              class="bot_logo"
              @click="goTalent(awemeInfo.author.authorid)"
            />
            <div>
              <p
                class="bot_tit"
                v-if="awemeInfo&&awemeInfo.author"
                @click="goTalent(awemeInfo.author.authorid)"
              >{{awemeInfo.author.nickname}}</p>
              <p class="tiktok" v-if="awemeInfo&&awemeInfo.author">抖音号：{{awemeInfo.author.uniqueid}}</p>
            </div>
          </div>
          <div class="total">
            <div>
              <p>粉丝总数</p>
              <p v-if="awemeInfo&&awemeInfo.author">{{format_num(awemeInfo.author.totalfans)}}</p>
            </div>
            <div>
              <p>点赞总数</p>
              <p v-if="awemeInfo&&awemeInfo.author">{{format_num(awemeInfo.author.totalfavorite)}}</p>
            </div>
          </div>
        </template>
        <div
          v-loading="loading"
          v-if="loading"
          class="loading"
          element-loading-text="拼命加载中..."
          element-loading-spinner="el-icon-loading"
        ></div>
      </div>
    </div>
    <div id="collectRoot">
      <div class="rightBox">
        <div class="btn_group">
          <button :class="{ active: input_btn == '0' }" @click="input_btn = '0'">基础信息</button>
          <button
            v-if="awemeInfo&&awemeInfo.aweme&&awemeInfo.aweme.pro_count"
            :class="{ active: input_btn == '1' }"
            @click="input_btn = '1'"
          >商品分析</button>
          <button :class="{ active: input_btn == '2' }" @click="input_btn = '2'">观众分析</button>
        </div>
        <div class="rig_box">
          <div class="rightBox-content">
            <information v-if="input_btn == '0'" />
            <goodsAnalysis v-if="input_btn == '1'" />
            <audienceAnalysis v-if="input_btn == '2'" />

            <!-- <div class="display_box"></div> -->
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import goodsAnalysis from './goodsAnalysis'; //商品分析
import information from './information'; //基础信息
import audienceAnalysis from './audienceAnalysis'; //观众分析
export default {
  data() {
    return {
      awemeInfo: [], //左侧列表
      goodsInfo: [],
      input_btn: 0,
      loading: false
    };
  },
  components: { goodsAnalysis, information, audienceAnalysis },
  computed: {},
  created() {},
  mounted() {
    if (this.$route.query.id) {
      this.id = this.$route.query.id;
    }
    this.info();
  },
  watch: {},
  methods: {
    // 收藏接口
    InsertCollection() {
      this.$axios
        .post('api/collection/InsertCollection', {
          CollectId: this.$route.query.id,
          Module: 2
        })
        .then(res => {
          if (res.data.code == 0) {
            this.$message({
              message: '收藏成功',
              type: 'success'
            });
            this.awemeInfo.awemecollection = 1;
            // this.awemeInfo = [];
            // this.info();
          } else {
            this.$message({
              message: '收藏失败',
              type: 'success'
            });
            this.awemeInfo.awemecollection = 0;
          }
        });
    },
    // 取消收藏
    CancelCollection() {
      this.$axios
        .post('/api/collection/CancelCollection', {
          CollectId: this.$route.query.id,
          Module: 2 //模块 1达人 2视频 3音乐 4话题 5商品
        })
        .then(res => {
          if (res.data.code == 0) {
            // this.awemeInfo = [];
            // this.info();
            this.$message({
              message: '取消收藏成功！',
              type: 'success',
              duration: 2000
            });
            this.awemeInfo.awemecollection = 0;
          } else {
            this.$message({
              message: '取消收藏失败！',
              type: 'error',
              duration: 2000
            });
            this.awemeInfo.awemecollection = 1;
          }
        })
        .catch(err => {
          console.log(err);
          this.$message({
            message: '取消收藏失败！',
            type: 'error',
            duration: 2000
            // offset: '400',
          });
        });
    },
    // 达人详情
    goTalent(id) {
      let router = this.$router.resolve({
        path: `/talent_main/tdetails/${id}/0`
      });
      window.open(router.href, '_blank');
    },
    // 跳转抖音视频
    dyVideo() {
      window.open(this.awemeInfo.aweme.url);
    },
    //   根据视频ID获取视频详情左侧
    info() {
      this.loading = true;
      this.$axios
        .get(`/api/aweme/info?api-version=2&awemeid=${this.$route.query.id}`)
        .then(result => {
          this.loading = false;
          if (result.data.code == 0) {
            this.awemeInfo = result.data.data;
            document.title = this.awemeInfo.aweme.title + '-抖音短视频数据分析-掌上精选';
          }
        })
        .catch(err => {});
    },
    onError() {
      this.$message.error(this.$t('prompt.copyFail'));
    },
    // d复制
    copy() {
      if (this.iscopy) return;
      setTimeout(() => {
        this.iscopy = false;
      }, 1000);

      this.$message({
        message: '复制成功！',
        type: 'success',
        duration: 1000,
        center: true
        // offset: 100,
      });

      this.iscopy = true;
    }
  }
};
</script>

<style lang="less" scoped>
.viedeDetails_main {
  margin-left: @margin-num;
  margin-right: @margin-num;
  margin-top: @margin-num;
  overflow: hidden;
  display: flex;
  height: calc(100vh - 94px);
  //   ele
  .el-popover__reference {
    width: 30px;
    height: 30px;
    cursor: pointer;
  }
  .copylink {
    display: inline-block;
    > img {
      width: 30px;
      height: 30px;
      cursor: pointer;
      margin-left: 5px;
    }
  }
  //
  .left_box {
    width: 300px;
    .left_info {
      width: 300px;
      min-height: 336px;
      background-color: #ffffff;
      border-radius: 4px;
      margin-bottom: 10px;
      padding: 20px;
      box-sizing: border-box;
      text-align: center;
      .info_box {
        text-align: left;
        display: flex;
        .logo {
          width: 50px;
          height: 50px;
          border-radius: 6px;
          margin-right: 10px;
          cursor: pointer;
          object-fit: cover;
        }
        .title {
          width: 196px;
          font-size: 16px;
          font-weight: 600;
          color: #222222;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 2;
          overflow: hidden;
          margin-bottom: 5px;
          &:hover {
            color: #ff924b;
            cursor: pointer;
          }
        }
      }
      .commonStyle {
        text-align: left;
        margin-bottom: 15px;
        > p {
          display: inline-block;
          &:nth-child(1) {
            font-size: 12px;
            color: #888888;
            margin-right: 25px;
          }
          &:nth-child(2) {
            font-size: 13px;
            color: #222222;
          }
        }
      }
      .mar_top {
        margin-top: 20px;
      }
      .bor_bot {
        border-bottom: solid 1px #efefef;
      }
      .add_col {
        width: 80px;
        height: 32px;
        border-radius: 4px;
        border: solid 1px #ff924b;
        margin: auto;
        margin-top: 15px;
        font-size: 14px;
        color: #ff924b;
        line-height: 28px;
      }
    }
    .bot_info {
      width: 300px;
      padding: 20px;
      background-color: #ffffff;
      border-radius: 4px;
      box-sizing: border-box;
      .bot_box {
        display: flex;
        .bot_logo {
          width: 51px;
          height: 51px;
          border-radius: 50%;
          margin-right: 10px;
          cursor: pointer;
        }
        > div {
          margin-top: 7px;
          .bot_tit {
            width: 200px;
            font-size: 16px;
            font-weight: 600;
            color: #222222;
            margin-bottom: 3px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            &:hover {
              color: #ff924b;
              cursor: pointer;
            }
          }
          .tiktok {
            font-size: 12px;

            color: #888888;
          }
        }
      }
      .total {
        margin-top: 20px;
        > div {
          display: flex;
          &:nth-child(1) {
            margin-bottom: 20px;
          }

          > p {
            align-self: center;
            &:nth-child(1) {
              margin-right: 25px;
              font-size: 12px;
              color: #888888;
            }
            &:nth-child(2) {
              font-size: 13px;
              color: #222222;
            }
          }
        }
      }
    }
  }
  #collectRoot {
    box-sizing: border-box;
    flex: 1;
    height: 100%;
    overflow: hidden;
    // margin-top: @margin-num;
    margin-left: @margin-num;
    // margin-right: @margin-num;
    background-color: #f1f1f1;
    .rig_box {
      width: 100%;
      height: calc(100% - 50px);
      border-radius: 4px;
      padding: 20px 0 3px;
      margin-top: 10px;
      -webkit-box-sizing: border-box;
      box-sizing: border-box;
      background: #fff;
      overflow: hidden;
    }
    // .rig_box {
    //   width: 100%;
    //   height: calc(100% - 50px);
    //   border-radius: 4px;
    //   padding: 20px 0px 3px 0px;
    //   margin-top: 10px;
    //   box-sizing: border-box;
    //   background: #fff;
    //   -webkit-box-sizing: border-box;
    //   overflow: hidden;
    // }
    .rightBox {
      width: 100%;
      position: relative;
      -webkit-box-sizing: border-box;
      box-sizing: border-box;
      height: 100%;
      -webkit-box-flex: 1;
      -ms-flex: 1;
      flex: 1;
      border-radius: 6px;
      .btn_group {
        text-align: left;
        .active {
          background-color: #fd7f2c;
          color: #ffffff !important;
        }
        button {
          font-size: 14px;
          color: #555;
          padding-left: 23px;
          padding-right: 23px;
          height: 40px;
          background-color: #fff;
          border-radius: 4px;
          margin-right: 7px;
          font-weight: 600;
        }
      }
    }
    .rightBox-content {
      position: relative;
      background-color: #ffffff;
      border-radius: 6px;
      // margin-top: 10px;
      height: calc(100% - 20px);
      // height: 100%;
      overflow: scroll;
      overflow-x: hidden;
    }
  }
}
</style>
